<?php
// 
//  security_model.php
//  ColdXin_CI
//  
//  Created by Will_Lee on 2011-05-01.
//  Copyright 2011 lishuzu. All rights reserved.
// 
 class Security_model extends CI_Model{
	function __construct(){
		parent::__construct();
		$this->user = $this->session->userdata('user') ? $this->session->userdata('user') : '';
	}
	//是否登录
 	function isLogin(){
		if ($this->session->userdata('user')) {
			return true;
		}else {
			return false;
		}
	}
	
	//是否登录
 	function isAdminLogin(){
		$userinfo = $this->session->userdata('adminuserinfo');
		$md5_username = substr(md5($this->user['username']), 0, 24);
		$md5_password = substr(md5($this->user['password']), 0, 24);
		if (empty($md5_username) || empty($md5_password) || empty($userinfo) || empty($this->user)) {
			return false;
		}
		if ($userinfo['username'] == $md5_username && $userinfo['password'] == $md5_password) {
			return true;
		}else {
			return false;
		}
	}
	
	//更新用户信息
	function update_user_session(){
		if ($this->user) {
			$this->load->model('user_model');
			$userinfo = $this->user_model->getuser('uid', $this->user['uid']);
			if ($userinfo) {
				$session_data = array(
					'user' => $userinfo
					);
				$this->session->unset_userdata('user');
				$this->session->set_userdata($session_data);
				return true;
			}
		}
		return false;
	}
	
	function checkself($uid){
		if ($this->user) {
			if ($uid == $this->user['uid']) {
				return 1;
			}
		}
		return 0;

	}
}
?>